package requests

import (
	"flyinfo/config"
	"strconv"

	"github.com/gin-gonic/gin"
)

type httpServer struct {
	config *config.Config
}

func New(config *config.Config) *httpServer {
	return &httpServer{
		config: config,
	}
}

func (h *httpServer) Run() error {
	if h.config.Server.Port == 0 {
		h.config.Server.Port = 4691
	}
	// gin.SetMode(gin.ReleaseMode)
	engine := gin.Default()

	engine.GET("/send", h.handlerSend)

	err := engine.Run(h.config.Server.Ip + ":" + strconv.Itoa(h.config.Server.Port))
	if err != nil {
		return err
	}

	return nil
}
